<template>
  <div>
    <welcome :say="say"></welcome>
    <img-card v-if="showImgCard" :papers="wallpagers" @getNum="setNum($event)"></img-card>
    <core-cta />
  </div>
</template>

<script>
export default {

  data() {
    return {
      showImgCard: false
    }
  },

  components: {
    Welcome: () => import('@/components/say/Welcome'),
    ImgCard: () => import('@/components/say/ImgCard'),
    CoreCta: () => import('@/components/core/Cta'),
  },

  async asyncData({params, $axios}){
    const { id } = params
    const say = await $axios.$get(`says/user${id}`)
    const {data: wallpagers} = await $axios.$get('wallpapers', {
      params: {
        query: {limit: 100 }
      }
    })
    return{
      say,
      wallpagers
    }
  },

  created(){
    this.init()
  },

  methods:{
    init(){
      if(this.$auth.state.user && this.$auth.state.user._id === this.say.user._id){
        this.showImgCard = true
      }
    },
    async setNum(id){
      this.say.wallpaper = id
      const say = await this.$axios.$put(`says/user${this.say._id}`, this.say)
      this.say = say
      this.init()
      this.$toast.success('设置成功')
      this.$vuetify.goTo(0)
    }
  }

}
</script>

<style>

</style>